/*
 * @描述: 找回密码数据请求
 * @版权所有: 广东国星科技有限公司
 * @商业授权: www.mscodecloud.com
 */
import { retrievePassword } from '@/services/userApi';
import { setAuthority } from '@/utils/authority';
import { reloadAuthorized } from '@/utils/Authorized';

export default {
  namespace: 'forgotPassword',

  state: {

  },

  effects: {
    *submit({ payload }, { call, put }) {
      const response = yield call(retrievePassword, payload);
      yield put({
        type: 'forgotPasswordHandle',
        payload: response
      });
      if (!response.message) return;
      return response;
    }
  },

  reducers: {
    forgotPasswordHandle(state, { payload }) {
      setAuthority('guest');
      reloadAuthorized();
      return {
        ...state
      };
    }
  }
};
